//
//  NoBagScrollView.m
//  crowd
//
//  Created by 马腾飞 on 16/5/8.
//  Copyright © 2016年 caocaod.com. All rights reserved.
//

#import "NoBagScrollView.h"
#import "MJRefresh.h"

@implementation NoBagScrollView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentOffset = CGPointZero;
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        self.alwaysBounceVertical = YES;
        self.bounces = YES;
        
        _wifiImage = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width-42)/2, (frame.size.height-42)/2-30, 42, 42)];
        _wifiImage.contentMode = UIViewContentModeScaleAspectFit;
        [_wifiImage setImage:[UIImage imageNamed:@"bag"]];
        [self addSubview:_wifiImage];
        
        _wifiLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (frame.size.height-42)/2+42+9-30, frame.size.width, 12)];
        _wifiLabel.text = @"暂无数据,下拉试试?";
        _wifiLabel.textAlignment = NSTextAlignmentCenter;
        _wifiLabel.font = [UIFont systemFontOfSize:12];
        _wifiLabel.textColor = RGB(191, 191, 191);
        [self addSubview:_wifiLabel];
        
        [self addMJRefreshHeader:@selector(upRefresh)];
        
    }
    return self;
}

- (void)addMJRefreshHeader:(SEL)downAction {
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:downAction];
    header.lastUpdatedTimeLabel.hidden = YES;
    self.mj_header = header;
}

- (void)upRefresh {
    if ([self.noBagScrollViewDelegate respondsToSelector:@selector(scrollViewLoadNewDataWithFlag:)]) {
        [self.noBagScrollViewDelegate scrollViewLoadNewDataWithFlag:self.flag];
    }
}
@end
